<template>
  <div class="swStTicketInformationCheck">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="refreshChange"
        @on-load="getList"
        :cell-style="cellStyle">
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menuRight">
          <el-button class="filter-item" type="primary" size="mini" @click="JiaRuBaoBiaoChaCuo()">加入报表差错</el-button>
          <el-button class="filter-item" type="primary" size="mini" @click="ACCXieCha()">清分协查</el-button>
          <el-button type="primary"  size="mini" @click="exportExcel">导出</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <addReportEditor ref="addReportEditor" @addReportSuccess="getList"></addReportEditor>
  </div>
</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import ElInput from "../../../../../node_modules/element-ui/packages/input/src/input";
  import { setSearchFiledsEmpty} from "../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
  import transitUtil from "../../../../api/subwayRat/transitUtil";
  import {tableOption,getSwStTicketInformationCheck,updateSwStTicketInformationCheck
  } from '../../../../api/subwayRat/conductorDifferences/passengersTransaction/swStTicketInformationCheck';
  import addReportEditor from '@/views/subwayRat/reportMondify/reportMistakeInfo/Editor';
  export default {
    components: {ElInput,addReportEditor},
    name: 'swStTicketInformationCheck',
    data() {
      return {
        type : 0,
        selectKeys:[], //存放对像
        selectKeyVals:[], //存放值
        option: tableOption,
        listLoading: true,
        searchForm:{
          lineCode:'',
          stationCode:''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : []
      }
    },
    computed: {
    },
    watch: {
    },
    created() {
    },
    mounted() {
    },
    methods: {
      setSearchFiledsEmpty,
      refreshChange() {
        this.getList()
      },
      async exportExcel(){ // 导出
        let p={};
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        Object.assign(p,this.searchForm);
        p.pageNo=1;
        p.pageSize=1000000000;
        if(this.selectKeys.length>0){
          exportDataToExcel(this.selectKeys,this.option.column,'票卡信息');
        }else {
          let res=await getSwStTicketInformationCheck(p);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'票卡信息');
        }
      },
      cellStyle({ row, column, rowIndex,columnIndex }) {
        if(7==columnIndex){
          if (row.diffAmount < 0) {
            return {
              color: "red",
            };
          }else if (row.diffAmount > 0) {
            return {
              color: "green",
            };
          }
        }
      },
      ACCXieCha(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要设置的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(0 != this.selectKeys[i].accDataStatus){
            this.$message.warning("请勾选待下发数据！");
            return
          }
        }
        let p = {
          ids : JSON.stringify(this.selectKeyVals),
          accDataStatus : 1
        };
        updateSwStTicketInformationCheck(p).then((res)=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
          }else{
            this.$message.error("操作失败！");
          }
        });
      },
      JiaRuBaoBiaoChaCuo(){
        if(this.selectKeys.length<=0 || this.selectKeys.length>1){
          this.$message.warning("请选择要加入的数据并且只选择一条！");
          return;
        }
        if(this.selectKeys[0].diffAmount == 0){
          this.$message.warning("请选择清分回馈回来后差异不为0的数据");
          return;
        }
        let param={
          resultIds:this.selectKeys[0].id,
          operatorTable:"sw_st_ticket_information_check",
          lineCode:this.selectKeys[0].submitLineCode,
          stationCode:this.selectKeys[0].submitStationCode,
          reprotTime:this.selectKeys[0].inputTime,
          reportNameId:3,
          userCodes:this.selectKeys[0].inputPersonCode,
          showType:3,
          dataSource:11,
	  errorAmount:this.selectKeys[0].diffAmount
        };
        this.$refs.addReportEditor.others_report_add_call(param);

      },
      async exportData(){ // 导出
        this.searchForm.pageNo=1;
        this.searchForm.pageSize=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'票卡信息');
        }else {
          let res=await getSwStTicketInformationCheck(this.searchForm);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'票卡信息');
        }
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        getSwStTicketInformationCheck(this.searchForm).then((response)=>{
          this.list = response.data.data
          this.listLoading = false
          this.page.total=response.data.total;
        });
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      }
    }
  }
</script>
<style lang="scss">
</style>
